package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.tanhua.dubbo.api.SettingsApi;
import com.tanhua.dubbo.mapper.SettingsMapper;
import com.tanhua.dubbo.pojo.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService(version = "1.0.0")
public class SettingsApiImpl implements SettingsApi {

    @Autowired
    private SettingsMapper settingsMapper;

    @Override
    public List<Settings> querySettings(Long userId) {
        return this.settingsMapper.selectList(new QueryWrapper<Settings>().eq("user_id", userId));
    }

    @Override
    public Integer setting(Boolean likeNotification, Boolean pinglunNotification, Boolean gonggaoNotification,Long userId) {

        Settings settings = new Settings();
        settings.setGonggaoNotification(gonggaoNotification);
        settings.setLikeNotification(likeNotification);
        settings.setPinglunNotification(pinglunNotification);
        settings.setUserId(userId);
        return  this.settingsMapper.update(settings,new UpdateWrapper<Settings>().eq("user_id",userId));
    }
}
